#!/bin/bash
set -e
CURPATH=`pwd`/$(dirname $0)
echo $CURPATH
hb build --help | grep patch > /dev/null
if [ $? -ne 0 ];then
echo "升级hb ..."
python3 -m pip uninstall ohos-build
python3 -m pip install --user ohos-build
fi
if [ -d $CURPATH/OpenHarmony-2.2-Beta2 ];then
echo "更新 OpenHarmony-2.2-Beta2 ..."
cd $CURPATH/OpenHarmony-2.2-Beta2
$CURPATH/repo sync
else
echo "下载 OpenHarmony-2.2-Beta2 ..."
mkdir -p $CURPATH/OpenHarmony-2.2-Beta2
cd $CURPATH/OpenHarmony-2.2-Beta2
$CURPATH/repo init -u https://gitee.com/openharmony/manifest.git -b OpenHarmony-2.2-Beta2 --no-repo-verify --depth=1
$CURPATH/repo sync -c
$CURPATH/repo forall -c 'git lfs pull'
cd -
fi
if [ -d $CURPATH/ingenic ];then
echo "更新device-ingenic"
cd $CURPATH/OpenHarmony-2.2-Beta2/device/ingenic
git pull
cd -
echo "更新device-vendor"
cd $CURPATH/OpenHarmony-2.2-Beta2/vendor/ingenic
git pull
cd -
else
echo "下载 Ingenic Device & Vendor ..."
mkdir -p $CURPATH/ingenic
cd $CURPATH/ingenic
git clone https://gitee.com/openharmony-sig/device_ingenic.git
git clone https://gitee.com/openharmony-sig/vendor_ingenic.git
cd -
echo "合并 Device & Vendor 到 OpenHarmony-2.2-Beta2"
mkdir -p $CURPATH/OpenHarmony-2.2-Beta2/device/ingenic
mkdir -p $CURPATH/OpenHarmony-2.2-Beta2/vendor/ingenic
mv $CURPATH/ingenic/device_ingenic/* $CURPATH/OpenHarmony-2.2-Beta2/device/ingenic
mv $CURPATH/ingenic/device_ingenic/.git $CURPATH/OpenHarmony-2.2-Beta2/device/ingenic
mv $CURPATH/ingenic/vendor_ingenic/* $CURPATH/OpenHarmony-2.2-Beta2/vendor/ingenic
mv $CURPATH/ingenic/vendor_ingenic/.git $CURPATH/OpenHarmony-2.2-Beta2/vendor/ingenic
fi
echo "1. 进入OpenHarmony-2.2-Beta2然后执行:"
echo "   hb set"
echo "   选择smartpen板级"
echo "2. 然后编译"
echo "   hb build -f --patch"
echo "3. 在out/x2000/smartpen_x2000_mmc下生成："
echo "   rootfs_ext4.img"
echo "   xImage"
echo "   uboot"
echo "4. 把uboot烧录到uboot分区，把xImage烧录到kernel分区，把rootfs_ext4.img烧录到文件系统分区。"
